package com.cc.pms.controller;


import com.cc.pms.domain.vo.*;
import com.cc.pms.service.*;
import com.cc.common.annotation.Anonymous;
import com.cc.common.core.domain.R;
import com.cc.common.core.page.PageQuery;
import com.cc.common.core.page.PageVo;
import com.cc.pms.domain.Team;
import com.cc.pms.domain.TeamApplication;
import com.cc.pms.domain.TeamChat;
import com.cc.pms.domain.UserChat;
import com.cc.pms.domain.vo.*;
import com.cc.pms.service.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/mine")
public class MineController {


    @Resource
    private IUserService iUserService;

    @Resource
    private ITeamApplicationService iTeamApplicationService;

    @Resource
    private ITeamMemberService iTeamMemberService;

    @Resource
    private IUserTagService iUserTagService;

    @Resource
    private ITeamService iTeamService;

    @Resource
    private ITeamChatService iTeamChatService;

    @Resource
    private IUserChatService iUserChatService;


    @GetMapping("/application/history")
    public R<PageVo<TeamApplicationVo>> queryApplicationHistory(PageQuery query){
        return R.ok(iTeamApplicationService.queryMineApplicationTeamHistory(query));
    }


    @PostMapping("/team/member/{teamId}/exit")
    public R<Boolean> memberExitTeam(@PathVariable Long teamId){
        return iTeamMemberService.exitTeam(teamId);
    }


    @Anonymous
    @PostMapping("/{userId}/update-tags")
    public R<Boolean> updateUserTags(@PathVariable Long userId , @RequestBody(required = false) Long[] tagIds){
       return iUserTagService.updateUserTagByUserId(userId ,tagIds);
    }


    @PostMapping("/update")
    public R<Boolean> updateUser(@RequestBody UserVo userVo){
        return iUserService.updateUser(userVo);
    }


    @GetMapping("/team/{teamId}/application/history")
    public R<PageVo<TeamApplicationVo>> queryTeamApplicationHistory(PageQuery query , @PathVariable Long teamId){
        return R.ok(iTeamApplicationService.queryManageApplicationTeamHistory(query, teamId));
    }


    @GetMapping("/team/manage/list")
    public R<PageVo<TeamVo>> queryManageTeam(PageQuery query , Team team){
        return R.ok(iTeamService.queryMineManageTeamVoPage(query ,team));
    }


    @PostMapping("/team/create")
    public R<Long> createTeam(@RequestBody Team team){
        return iTeamService.create(team);
    }

    @PostMapping("/team/application/handle")
    public R<Boolean> handleTeamApply(@RequestBody TeamApplication application){
        return iTeamApplicationService.handleApplication(application);
    }

    @PostMapping("/team/member/{teamId}/force/{userId}/exit")
    public R<Boolean> forceMemberExit(@PathVariable Long teamId , @PathVariable Long userId){
        return iTeamMemberService.forcingMemberExitTeam(teamId , userId);
    }


    @PostMapping("/team/chat/send")
    public R<Long> teamChat(@RequestBody TeamChat teamChat){
        return iTeamChatService.sendTeamChatMessage(teamChat);
    }


    @GetMapping("/team/{teamId}/chat")
    public R<List<TeamChatVo>> teamChatList(@PathVariable Long teamId){
        return R.ok(iTeamChatService.queryTeamChatRecord(teamId));
    }


    @PostMapping("/user/chat/send")
    public R<Long> userChat(@RequestBody UserChat userChat){
        return iUserChatService.sendChat(userChat);
    }

    @GetMapping("/user/chat/detail")
    public R<List<UserChatVo>> userChatDetail(UserChat userChat){
        return R.ok(iUserChatService.queryMineChatDetail(userChat.getReceiverId()));
    }

    @GetMapping("/user/chat/list")
    public R<List<UserChatVo>> userChatList(){
        return R.ok(iUserChatService.queryMineChatList());
    }


    @GetMapping("/user/tag/list")
    public R<List<TagVo>> queryUserTag(){
        return R.ok(iUserTagService.queryUserTag());
    }


    @GetMapping("/join/team/list")
    public R<PageVo<TeamVo>> queryJoinTeamList(PageQuery query ,Team team){
        return R.ok(iTeamService.queryJoinTeamVoPage(query,team));
    }


}
